home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / rcs55.zip / RLOG.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  34KB  |  1,141 lines

  1. /*
  2.  *                       RLOG    operation
  3.  */
  4. /*****************************************************************************
  5.  *                       print contents of RCS files
  6.  *****************************************************************************
  7.  */
  8.  
  9. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  10.    Copyright 1990 by Paul Eggert
  11.    Distributed under license by the Free Software Foundation, Inc.
  12.  
  13. This file is part of RCS.
  14.  
  15. RCS is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation; either version 1, or (at your option)
  18. any later version.
  19.  
  20. RCS is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. GNU General Public License for more details.
  24.  
  25. You should have received a copy of the GNU General Public License
  26. along with RCS; see the file COPYING.  If not, write to
  27. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  28.  
  29. Report problems and direct all questions to:
  30.  
  31.     rcs-bugs@cs.purdue.edu
  32.  
  33. */
  34.  
  35.  
  36.  
  37.  
  38. /* $Log: rlog.c%v $
  39.  * Revision 1.2  1991/08/23  13:38:56  SGP
  40.  * Ported to MSDOS using Borland C++
  41.  *
  42.  * Revision 5.5  1990/11/01  05:03:55  eggert
  43.  * Permit arbitrary data in logs and comment leaders.
  44.  *
  45.  * Revision 5.4  1990/10/04  06:30:22  eggert
  46.  * Accumulate exit status across files.
  47.  *
  48.  * Revision 5.3  1990/09/11  02:41:16  eggert
  49.  * Plug memory leak.
  50.  *
  51.  * Revision 5.2  1990/09/04  08:02:33  eggert
  52.  * Count RCS lines better.
  53.  *
  54.  * Revision 5.0  1990/08/22  08:13:48  eggert
  55.  * Remove compile-time limits; use malloc instead.  Add setuid support.
  56.  * Switch to GMT.
  57.  * Report dates in long form, to warn about dates past 1999/12/31.
  58.  * Change "added/del" message to make room for the longer dates.
  59.  * Don't generate trailing white space.  Add -V.  Ansify and Posixate.
  60.  *
  61.  * Revision 4.7  89/05/01  15:13:48  narten
  62.  * changed copyright header to reflect current distribution rules
  63.  * 
  64.  * Revision 4.6  88/08/09  19:13:28  eggert
  65.  * Check for memory exhaustion; don't access freed storage.
  66.  * Shrink stdio code size; remove lint.
  67.  * 
  68.  * Revision 4.5  87/12/18  11:46:38  narten
  69.  * more lint cleanups (Guy Harris)
  70.  * 
  71.  * Revision 4.4  87/10/18  10:41:12  narten
  72.  * Updating version numbers
  73.  * Changes relative to 1.1 actually relative to 4.2
  74.  * 
  75.  * Revision 1.3  87/09/24  14:01:10  narten
  76.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  77.  * warnings)
  78.  * 
  79.  * Revision 1.2  87/03/27  14:22:45  jenkins
  80.  * Port to suns
  81.  * 
  82.  * Revision 4.2  83/12/05  09:18:09  wft
  83.  * changed rewriteflag to external.
  84.  * 
  85.  * Revision 4.1  83/05/11  16:16:55  wft
  86.  * Added -b, updated getnumericrev() accordingly.
  87.  * Replaced getpwuid() with getcaller().
  88.  * 
  89.  * Revision 3.7  83/05/11  14:24:13  wft
  90.  * Added options -L and -R;
  91.  * Fixed selection bug with -l on multiple files.
  92.  * Fixed error on dates of the form -d'>date' (rewrote getdatepair()).
  93.  * 
  94.  * Revision 3.6  82/12/24  15:57:53  wft
  95.  * shortened output format.
  96.  *
  97.  * Revision 3.5  82/12/08  21:45:26  wft
  98.  * removed call to checkaccesslist(); used DATEFORM to format all dates;
  99.  * removed unused variables.
  100.  *
  101.  * Revision 3.4  82/12/04  13:26:25  wft
  102.  * Replaced getdelta() with gettree(); removed updating of field lockedby.
  103.  *
  104.  * Revision 3.3  82/12/03  14:08:20  wft
  105.  * Replaced getlogin with getpwuid(), %02d with %.2d, fancydate with PRINTDATE.
  106.  * Fixed printing of nil, removed printing of Suffix,
  107.  * added shortcut if no revisions are printed, disambiguated struct members.
  108.  *
  109.  * Revision 3.2  82/10/18  21:09:06  wft
  110.  * call to curdir replaced with getfullRCSname(),
  111.  * fixed call to getlogin(), cosmetic changes on output,
  112.  * changed conflicting long identifiers.
  113.  *
  114.  * Revision 3.1  82/10/13  16:07:56  wft
  115.  * fixed type of variables receiving from getc() (char -> int).
  116.  */
  117.  
  118.  
  119.  
  120. #include "rcsbase.h"
  121.  
  122. struct  lockers {                     /* lockers in locker option; stored   */
  123.      const char         * login;      /* lockerlist                         */
  124.      struct     lockers * lockerlink;
  125.      }  ;
  126.  
  127. struct  stateattri {                  /* states in state option; stored in  */
  128.      const char         * status;     /* statelist                          */
  129.      struct  stateattri * nextstate;
  130.      }  ;
  131.  
  132. struct  authors {                     /* login names in author option;      */
  133.      const char         * login;      /* stored in authorlist               */
  134.      struct     authors * nextauthor;
  135.      }  ;
  136.  
  137. struct Revpairs{                      /* revision or branch range in -r     */
  138.      unsigned          numfld;     /* option; stored in revlist        */
  139.      const char         * strtrev;
  140.      const char         * endrev;
  141.      struct  Revpairs   * rnext;
  142.      } ;
  143.  
  144. struct Datepairs{                     /* date range in -d option; stored in */
  145.      char               strtdate[datesize];   /* duelst and datelist      */
  146.      char               enddate[datesize];
  147.      struct  Datepairs  * dnext;
  148.      };
  149.  
  150. static char extractdelta P((const struct hshentry*));
  151. static int checkrevpair P((const char*,const char*));
  152. static int readdeltalog P((void));
  153. static void cleanup P((void));
  154. static void extdate P((struct hshentry*));
  155. static void exttree P((struct hshentry*));
  156. static void getauthor P((char*));
  157. static void getdatepair P((char*));
  158. static void getlocker P((char*));
  159. static void getnumericrev P((void));
  160. static void getrevpairs P((char*));
  161. static void getscript P((struct hshentry*));
  162. static void getstate P((char*));
  163. static void putabranch P((const struct hshentry*));
  164. static void putadelta P((const struct hshentry*,const struct hshentry*,int));
  165. static void putforest P((const struct branchhead*));
  166. static void putree P((const struct hshentry*));
  167. static void putrunk P((void));
  168. static void recentdate P((const struct hshentry*,struct Datepairs*));
  169. static void trunclocks P((void));
  170.  
  171. static const char *insDelFormat;
  172. static int branchflag;    /*set on -b */
  173. static int exitstatus;
  174. static int lockflag;
  175. static int revno;    /* number of revision chosen */
  176. static struct Datepairs *datelist, *duelst;
  177. static struct Revpairs *revlist, *Revlst;
  178. static struct authors *authorlist;
  179. static struct lockers *lockerlist;
  180. static struct stateattri *statelist;
  181.  
  182.  
  183. mainProg(rlogId, "rlog", "$Id: rlog.c%v 1.2 1991/08/23 13:38:56 SGP Exp $")
  184. {
  185.     static const char cmdusage[] =
  186.         "\nrlog usage: rlog -{bhLRt} -ddates -l[lockers] -rrevs -sstates -w[logins] -Vn file ...";
  187.  
  188.     struct Datepairs *currdate;
  189.     const char *accessListString, *accessFormat, *commentFormat;
  190.     const char *headFormat, *symbolFormat;
  191.     const struct access *curaccess;
  192.     const struct assoc *curassoc;
  193.     const struct lock *currlock;
  194.     int descflag, selectflag;
  195.     int onlylockflag;  /* print only files with locks */
  196.     int selectop;  /* print only some revisions */
  197.     int onlyRCSflag;  /* print only RCS file name */
  198.  
  199.     initid();
  200.  
  201.         descflag = selectflag = true;
  202.     onlylockflag = selectop = onlyRCSflag = false;
  203.  
  204.         while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
  205.                 switch ((*argv)[1]) {
  206.  
  207.         case 'L':
  208.             onlylockflag = true;
  209.             break;
  210.  
  211.         case 'R':
  212.             onlyRCSflag =true;
  213.             break;
  214.  
  215.                 case 'l':
  216.                         selectop = true;
  217.                         lockflag = true;
  218.                         getlocker( (*argv)+2 );
  219.                         break;
  220.  
  221.                 case 'b':
  222.                         selectop = true;
  223.                         branchflag = true;
  224.                         break;
  225.  
  226.                 case 'r':
  227.                         selectop = true;
  228.                         getrevpairs( (*argv)+2 );
  229.                         break;
  230.  
  231.                 case 'd':
  232.                         selectop = true;
  233.                         getdatepair( (*argv)+2 );
  234.                         break;
  235.  
  236.                 case 's':
  237.                         selectop = true;
  238.                         getstate( (*argv)+2);
  239.                         break;
  240.  
  241.                 case 'w':
  242.                         selectop = true;
  243.                         getauthor( (*argv)+2);
  244.                         break;
  245.  
  246.                 case 'h':
  247.                         if ( ! selectflag ) warn("-t overrides -h.");
  248.                         else    descflag = false;
  249.                         break;
  250.  
  251.                 case 't':
  252.                         selectflag = false;
  253.                         if ( ! descflag ) warn("-t overrides -h.");
  254.                         descflag = true;
  255.                         break;
  256.  
  257.         case 'V':
  258.             setRCSversion(*argv);
  259.             break;
  260.  
  261.                 default:
  262.             faterror("unknown option: %s%s", *argv, cmdusage);
  263.  
  264.                 };
  265.         } /* end of option processing */
  266.  
  267.     if (argc<1) faterror("no input file%s", cmdusage);
  268.  
  269.     if (RCSversion < VERSION(5)) {
  270.         accessListString = "\naccess list:   ";
  271.         accessFormat = "  %s";
  272.         commentFormat = "\ncomment leader:  \"";
  273.         headFormat = "\nRCS file:        %s;   Working file:    %s\nhead:           %s%s\nbranch:         %s%s\nlocks:         ";
  274.         insDelFormat = "  lines added/del: %lu/%lu";
  275.         symbolFormat = "  %s: %s;";
  276.     } else {
  277.         accessListString = "\naccess list:";
  278.         accessFormat = "\n\t%s";
  279.         commentFormat = "\ncomment leader: \"";
  280.         headFormat = "\nRCS file: %s\nWorking file: %s\nhead:%s%s\nbranch:%s%s\nlocks:%s";
  281.         insDelFormat = "  lines: +%lu -%lu";
  282.         symbolFormat = "\n\t%s: %s";
  283.     }
  284.  
  285.         /* now handle all filenames */
  286.         do {
  287.         finptr = NULL;
  288.         ffree();
  289.  
  290.         if (!pairfilenames(argc, argv, rcsreadopen, true, false))
  291.         continue;
  292.  
  293.             /* now RCSfilename contains the name of the RCS file, and finptr
  294.              * the file descriptor. Workfilename contains the name of the
  295.              * working file.
  296.              */
  297.  
  298.         /* Keep only those locks given by -l.  */
  299.         if (lockflag)
  300.         trunclocks();
  301.  
  302.             /* do nothing if -L is given and there are no locks*/
  303.         if (onlylockflag && !Locks)
  304.         continue;
  305.  
  306.         if ( onlyRCSflag ) {
  307.         aprintf(stdout, "%s\n", RCSfilename);
  308.         continue;
  309.         }
  310.             /*   print RCS filename , working filename and optional
  311.                  administrative information                         */
  312.             /* could use getfullRCSname() here, but that is very slow */
  313.         aprintf(stdout, headFormat, RCSfilename, workfilename,
  314.             Head ? " " : "",  Head ? Head->num : "",
  315.             Dbranch ? " " : "",  Dbranch ? Dbranch : "",
  316.             StrictLocks ? " strict" : ""
  317.         );
  318.             currlock = Locks;
  319.             while( currlock ) {
  320.         aprintf(stdout, symbolFormat, currlock->login,
  321.                                 currlock->delta->num);
  322.                 currlock = currlock->nextlock;
  323.             }
  324.             if (StrictLocks && RCSversion<VERSION(5))
  325.         aputs("  strict", stdout);
  326.  
  327.         aputs(accessListString, stdout);      /*  print access list  */
  328.             curaccess = AccessList;
  329.             while(curaccess) {
  330.         aprintf(stdout, accessFormat, curaccess->login);
  331.                 curaccess = curaccess->nextaccess;
  332.             }
  333.  
  334.         aputs("\nsymbolic names:", stdout);   /*  print symbolic names   */
  335.         for (curassoc=Symbols; curassoc; curassoc=curassoc->nextassoc)
  336.         aprintf(stdout, symbolFormat, curassoc->symbol, curassoc->num);
  337.         aputs(commentFormat, stdout);
  338.         awrite(Comment.string, Comment.size, stdout);
  339.         aputs("\"\n", stdout);
  340.         if (VERSION(5)<=RCSversion  ||  Expand != KEYVAL_EXPAND)
  341.         aprintf(stdout, "keyword substitution: %s\n",
  342.             expand_names[Expand]
  343.         );
  344.  
  345.             gettree();
  346.  
  347.         aprintf(stdout, "total revisions: %d", TotalDeltas);
  348.  
  349.             if ( Head == nil || !selectflag || !descflag) {
  350.         afputc('\n',stdout);
  351.         if (descflag) aputs("description:\n", stdout);
  352.                 getdesc(descflag);
  353.         goto rlogend;
  354.             }
  355.  
  356.  
  357.             getnumericrev();    /* get numeric revision or branch names */
  358.             revno = 0;
  359.  
  360.             exttree(Head);
  361.  
  362.             /*  get most recently date of the dates pointed by duelst  */
  363.             currdate = duelst;
  364.             while( currdate) {
  365.                 recentdate(Head, currdate);
  366.                 currdate = currdate->dnext;
  367.         }
  368.  
  369.             extdate(Head);
  370.  
  371.             /*  reinitialize the date specification list   */
  372.             currdate = duelst;
  373.             while(currdate) {
  374.                 VOID sprintf(currdate->strtdate,DATEFORM,0,0,0,0,0,0);
  375.                 currdate = currdate->dnext;
  376.             }
  377.  
  378.             if ( selectop || ( selectflag && descflag) )
  379.         aprintf(stdout, ";\tselected revisions: %d", revno);
  380.         afputc('\n', stdout);
  381.         if (descflag) aputs("description:\n", stdout);
  382.             getdesc(descflag);
  383.             if (selectflag && descflag && revno) {
  384.         while (readdeltalog())
  385.             ;
  386.                 putrunk();
  387.                 putree(Head);
  388.         if (nexttok != EOFILE)
  389.             fatserror("expecting EOF");
  390.             }
  391.     rlogend:
  392.         aputs("=============================================================================\n",stdout);
  393.     } while (cleanup(),
  394.          ++argv, --argc >= 1);
  395.     exitmain(exitstatus);
  396. }
  397.  
  398.     static void
  399. cleanup()
  400. {
  401.     if (nerror) exitstatus = EXIT_FAILURE;
  402.     if (finptr) ffclose(finptr);
  403. }
  404.  
  405. #if lint
  406. #    define exiterr rlogExit
  407. #endif
  408.     exiting void
  409. exiterr()
  410. {
  411.     _exit(EXIT_FAILURE);
  412. }
  413.  
  414.  
  415.  
  416.     static void
  417. putrunk()
  418. /*  function:  print revisions chosen, which are in trunk      */
  419.  
  420. {
  421.     register const struct hshentry *ptr;
  422.  
  423.     for (ptr = Head;  ptr;  ptr = ptr->next)
  424.         putadelta(ptr, ptr->next, true);
  425. }
  426.  
  427.  
  428.  
  429.     static void
  430. putree(const struct hshentry *root)
  431. /*   function: print delta tree (not including trunk) in reverse
  432.                order on each branch                                        */
  433.  
  434. {
  435.         if ( root == nil ) return;
  436.  
  437.         putree(root->next);
  438.  
  439.         putforest(root->branches);
  440. }
  441.  
  442.  
  443.  
  444.  
  445.     static void
  446. putforest(const struct branchhead *branchroot)
  447. /*   function:  print branches that has the same direct ancestor    */
  448. {
  449.  
  450.         if ( branchroot == nil ) return;
  451.  
  452.         putforest(branchroot->nextbranch);
  453.  
  454.         putabranch(branchroot->hsh);
  455.         putree(branchroot->hsh);
  456. }
  457.  
  458.  
  459.  
  460.  
  461.     static void
  462. putabranch(const struct hshentry *root)
  463. /*   function  :  print one branch     */
  464.  
  465. {
  466.  
  467.         if ( root == nil) return;
  468.  
  469.         putabranch(root->next);
  470.  
  471.         putadelta(root, root, false);
  472. }
  473.  
  474.  
  475.  
  476.  
  477.  
  478.     static void
  479. putadelta(register const struct hshentry *node,
  480.           register const struct hshentry *editscript,
  481.           int trunk)
  482. /*  function: Print delta node if node->selector is set.        */
  483. /*      editscript indicates where the editscript is stored     */
  484. /*      trunk indicated whether this node is in trunk           */
  485. {
  486.     const struct branchhead *newbranch;
  487.     struct buf branchnum;
  488.  
  489.     if (!node->selector)
  490.             return;
  491.  
  492.     aprintf(stdout,
  493.         "----------------------------\nrevision %s", node->num
  494.     );
  495.         if ( node->lockedby )
  496.        aprintf(stdout, "\tlocked by: %s;", node->lockedby);
  497.  
  498.     aputs("\ndate: ",stdout);
  499.     printdate(stdout, node->date, " ");
  500.     aprintf(stdout, ";  author: %s;  state: %s;",
  501.         node->author, node->state
  502.     );
  503.  
  504.         if ( editscript )
  505.            if(trunk)
  506.           aprintf(stdout, insDelFormat,
  507.                              editscript->deletelns, editscript->insertlns);
  508.            else
  509.           aprintf(stdout, insDelFormat,
  510.                              editscript->insertlns, editscript->deletelns);
  511.  
  512.         newbranch = node->branches;
  513.         if ( newbranch ) {
  514.        bufautobegin(&branchnum);
  515.        aputs("\nbranches:", stdout);
  516.            while( newbranch ) {
  517.         getbranchno(newbranch->hsh->num, &branchnum);
  518.         aprintf(stdout, "  %s;", branchnum.string);
  519.                 newbranch = newbranch->nextbranch;
  520.            }
  521.        bufautoend(&branchnum);
  522.         }
  523.  
  524.     afputc('\n', stdout);
  525.     awrite(node->log.string, node->log.size, stdout);
  526. }
  527.  
  528.  
  529.  
  530.  
  531.  
  532.     static int
  533. readdeltalog()
  534. /*  Function : get the log message and skip the text of a deltatext node.
  535.  *             Return false if current block does not start with a number.
  536.  *             Assumes the current lexeme is not yet in nexttok; does not
  537.  *             advance nexttok.
  538.  */
  539. {
  540.         register struct  hshentry  * Delta;
  541.     struct buf logbuf;
  542.  
  543.         nextlex();
  544.         if ( !(Delta = getnum() )) return(false);
  545.     getkeystring(Klog);
  546.     bufautobegin(&logbuf);
  547.     Delta->log = savestring(&logbuf);
  548.     /*
  549.      * Do the following instead of bufautoend(&logbuf),
  550.      * because the buffer must survive until we are done with the file.
  551.      */
  552.     Delta->log.string = (char *)fremember(testrealloc(
  553.         (malloc_type)logbuf.string,
  554.         Delta->log.size
  555.     ));
  556.  
  557.         nextlex();
  558.     while (nexttok==ID && strcmp(NextString,Ktext)!=0)
  559.         ignorephrase();
  560.     getkeystring(Ktext);
  561.         Delta->insertlns = Delta->deletelns = 0;
  562.         if ( Delta != Head)
  563.                 getscript(Delta);
  564.         else
  565.                 readstring();
  566.         return true;
  567. }
  568.  
  569.  
  570.  
  571.     static void
  572. getscript(struct hshentry *Delta)
  573. /*   function:  read edit script of Delta and count how many lines added  */
  574. /*              and deleted in the script                                 */
  575.  
  576. {
  577.         int ed;   /*  editor command  */
  578.     register FILE * fin;
  579.         register  int   c;
  580.     register unsigned long i;
  581.     struct diffcmd dc;
  582.  
  583.     fin = finptr;
  584.     initdiffcmd(&dc);
  585.     while (0  <=  (ed = getdiffcmd(fin,SDELIM,(FILE *)0,&dc)))
  586.         if (!ed)
  587.                  Delta->deletelns += dc.nlines;
  588.         else {
  589.                  /*  skip scripted lines  */
  590.          i = dc.nlines;
  591.          Delta->insertlns += i;
  592.          do {
  593.              while ((c=getc(fin)) != '\n')
  594.             if (c==EOF  ||  c==SDELIM && (c=getc(fin))!=SDELIM) {
  595.                 if (c==EOF || i!=1)
  596.                 fatserror("unexpected end to edit script");
  597.                 nextc = c;
  598.                 return;
  599.             }
  600.              ++rcsline;
  601.          } while (--i);
  602.             }
  603.     nextc = getc(fin);
  604. }
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.     static void
  613. exttree(struct hshentry *root)
  614. /*  function: select revisions , starting with root             */
  615.  
  616. {
  617.     const struct branchhead *newbranch;
  618.  
  619.         if (root == nil) return;
  620.  
  621.     root->selector = extractdelta(root);
  622.         exttree(root->next);
  623.  
  624.         newbranch = root->branches;
  625.         while( newbranch ) {
  626.             exttree(newbranch->hsh);
  627.             newbranch = newbranch->nextbranch;
  628.         }
  629. }
  630.  
  631.  
  632.  
  633.  
  634.     static void
  635. getlocker(char *argv)
  636. /*   function : get the login names of lockers from command line   */
  637. /*              and store in lockerlist.                           */
  638.  
  639. {
  640.         register char c;
  641.         struct   lockers   * newlocker;
  642.         argv--;
  643.         while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  644.                  c == '\n' || c == ';')  ;
  645.         if (  c == '\0') {
  646.             lockerlist=nil;
  647.             return;
  648.         }
  649.  
  650.         while( c != '\0' ) {
  651.         newlocker = talloc(struct lockers);
  652.             newlocker->lockerlink = lockerlist;
  653.             newlocker->login = argv;
  654.             lockerlist = newlocker;
  655.             while ( ( c = (*++argv)) != ',' && c != '\0' && c != ' '
  656.                        && c != '\t' && c != '\n' && c != ';') ;
  657.             *argv = '\0';
  658.             if ( c == '\0' ) return;
  659.             while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  660.                      c == '\n' || c == ';')  ;
  661.         }
  662. }
  663.  
  664.  
  665.  
  666.     static void
  667. getauthor(char *argv)
  668. /*   function:  get the author's name from command line   */
  669. /*              and store in authorlist                   */
  670.  
  671. {
  672.         register    c;
  673.         struct     authors  * newauthor;
  674.  
  675.         argv--;
  676.         while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  677.                  c == '\n' || c == ';')  ;
  678.         if ( c == '\0' ) {
  679.         authorlist = talloc(struct authors);
  680.         authorlist->login = getcaller();
  681.             authorlist->nextauthor  = nil;
  682.             return;
  683.         }
  684.  
  685.         while( c != '\0' ) {
  686.         newauthor = talloc(struct authors);
  687.             newauthor->nextauthor = authorlist;
  688.             newauthor->login = argv;
  689.             authorlist = newauthor;
  690.             while( ( c = *++argv) != ',' && c != '\0' && c != ' '
  691.                      && c != '\t' && c != '\n' && c != ';') ;
  692.             * argv = '\0';
  693.             if ( c == '\0') return;
  694.             while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  695.                      c == '\n' || c == ';')  ;
  696.         }
  697. }
  698.  
  699.  
  700.  
  701.  
  702.     static void
  703. getstate(char *argv)
  704. /*   function :  get the states of revisions from command line  */
  705. /*               and store in statelist                         */
  706.  
  707. {
  708.         register  char  c;
  709.         struct    stateattri    *newstate;
  710.  
  711.         argv--;
  712.         while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  713.                  c == '\n' || c == ';')  ;
  714.         if ( c == '\0'){
  715.         warn("missing state attributes after -s options");
  716.             return;
  717.         }
  718.  
  719.         while( c != '\0' ) {
  720.         newstate = talloc(struct stateattri);
  721.             newstate->nextstate = statelist;
  722.             newstate->status = argv;
  723.             statelist = newstate;
  724.             while( (c = (*++argv)) != ',' && c != '\0' && c != ' '
  725.                     && c != '\t' && c != '\n' && c != ';')  ;
  726.             *argv = '\0';
  727.             if ( c == '\0' ) return;
  728.             while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  729.                      c == '\n' || c == ';')  ;
  730.         }
  731. }
  732.  
  733.  
  734.  
  735.     static void
  736. trunclocks()
  737. /*  Function:  Truncate the list of locks to those that are held by the  */
  738. /*             id's on lockerlist. Do not truncate if lockerlist empty.  */
  739.  
  740. {
  741.     const struct lockers *plocker;
  742.         struct lock     * plocked,  * nextlocked;
  743.  
  744.         if ( (lockerlist == nil) || (Locks == nil)) return;
  745.  
  746.         /* shorten Locks to those contained in lockerlist */
  747.         plocked = Locks;
  748.         Locks = nil;
  749.         while( plocked != nil) {
  750.             plocker = lockerlist;
  751.             while((plocker != nil) && ( strcmp(plocker->login, plocked->login)!=0))
  752.                 plocker = plocker->lockerlink;
  753.             nextlocked = plocked->nextlock;
  754.             if ( plocker != nil) {
  755.                 plocked->nextlock = Locks;
  756.                 Locks = plocked;
  757.             }
  758.             plocked = nextlocked;
  759.         }
  760. }
  761.  
  762.  
  763.  
  764.     static void
  765. recentdate(const struct hshentry *root, struct Datepairs *pd)
  766. /*  function:  Finds the delta that is closest to the cutoff date given by   */
  767. /*             pd among the revisions selected by exttree.                   */
  768. /*             Successively narrows down the interval given by pd,           */
  769. /*             and sets the strtdate of pd to the date of the selected delta */
  770. {
  771.     const struct branchhead *newbranch;
  772.  
  773.     if ( root == nil) return;
  774.     if (root->selector) {
  775.              if ( cmpnum(root->date, pd->strtdate) >= 0 &&
  776.                   cmpnum(root->date, pd->enddate) <= 0)
  777.         VOID strcpy(pd->strtdate, root->date);
  778.         }
  779.  
  780.         recentdate(root->next, pd);
  781.         newbranch = root->branches;
  782.         while( newbranch) {
  783.            recentdate(newbranch->hsh, pd);
  784.            newbranch = newbranch->nextbranch;
  785.     }
  786. }
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.     static void
  794. extdate(struct hshentry *root)
  795. /*  function:  select revisions which are in the date range specified     */
  796. /*             in duelst  and datelist, start at root                     */
  797.  
  798. {
  799.     const struct branchhead *newbranch;
  800.     const struct Datepairs *pdate;
  801.  
  802.         if ( root == nil) return;
  803.  
  804.         if ( datelist || duelst) {
  805.             pdate = datelist;
  806.             while( pdate ) {
  807.                 if ( (pdate->strtdate)[0] == '\0' || cmpnum(root->date,pdate->strtdate) >= 0){
  808.                    if ((pdate->enddate)[0] == '\0' || cmpnum(pdate->enddate,root->date) >= 0)
  809.                         break;
  810.                 }
  811.                 pdate = pdate->dnext;
  812.             }
  813.             if ( pdate == nil) {
  814.                 pdate = duelst;
  815.         for (;;) {
  816.            if (!pdate) {
  817.             root->selector = false;
  818.             break;
  819.            }
  820.                    if ( cmpnum(root->date, pdate->strtdate) == 0)
  821.                       break;
  822.                    pdate = pdate->dnext;
  823.                 }
  824.             }
  825.         }
  826.     if (root->selector)
  827.         ++revno;
  828.  
  829.         extdate(root->next);
  830.  
  831.         newbranch = root->branches;
  832.         while( newbranch ) {
  833.            extdate(newbranch->hsh);
  834.            newbranch = newbranch->nextbranch;
  835.         }
  836. }
  837.  
  838.  
  839.  
  840.     static char
  841. extractdelta(const struct hshentry *pdelta)
  842. /*  function:  compare information of pdelta to the authorlist, lockerlist,*/
  843. /*             statelist, revlist and yield true if pdelta is selected.    */
  844.  
  845. {
  846.     const struct lock *plock;
  847.     const struct stateattri *pstate;
  848.     const struct authors *pauthor;
  849.     const struct Revpairs *prevision;
  850.     unsigned length;
  851.  
  852.     if ((pauthor = authorlist)) /* only certain authors wanted */
  853.         while (strcmp(pauthor->login, pdelta->author) != 0)
  854.         if (!(pauthor = pauthor->nextauthor))
  855.             return false;
  856.     if ((pstate = statelist)) /* only certain states wanted */
  857.         while (strcmp(pstate->status, pdelta->state) != 0)
  858.         if (!(pstate = pstate->nextstate))
  859.             return false;
  860.     if (lockflag) /* only locked revisions wanted */
  861.         for (plock = Locks;  ;  plock = plock->nextlock)
  862.         if (!plock)
  863.             return false;
  864.         else if (plock->delta == pdelta)
  865.             break;
  866.     if ((prevision = Revlst)) /* only certain revs or branches wanted */
  867.         for (;;) {
  868.                 length = prevision->numfld;
  869.         if (
  870.             countnumflds(pdelta->num) == length+(length&1) &&
  871.             0 <= compartial(pdelta->num, prevision->strtrev, length) &&
  872.             0 <= compartial(prevision->endrev, pdelta->num, length)
  873.         )
  874.              break;
  875.         if (!(prevision = prevision->rnext))
  876.             return false;
  877.             }
  878.     return true;
  879. }
  880.  
  881.  
  882.  
  883.     static void
  884. getdatepair(char *argv)
  885. /*  function:  get time range from command line and store in datelist if    */
  886. /*             a time range specified or in duelst if a time spot specified */
  887.  
  888. {
  889.         register   char         c;
  890.         struct     Datepairs    * nextdate;
  891.     const char        * rawdate;
  892.     int                     switchflag;
  893.  
  894.         argv--;
  895.         while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  896.                  c == '\n' || c == ';')  ;
  897.         if ( c == '\0' ) {
  898.         warn("missing date/time after -d");
  899.             return;
  900.         }
  901.  
  902.         while( c != '\0' )  {
  903.         switchflag = false;
  904.         nextdate = talloc(struct Datepairs);
  905.             if ( c == '<' ) {   /*   case: -d <date   */
  906.                 c = *++argv;
  907.                 (nextdate->strtdate)[0] = '\0';
  908.         } else if (c == '>') { /* case: -d'>date' */
  909.         c = *++argv;
  910.         (nextdate->enddate)[0] = '\0';
  911.         switchflag = true;
  912.         } else {
  913.                 rawdate = argv;
  914.         while( c != '<' && c != '>' && c != ';' && c != '\0')
  915.              c = *++argv;
  916.                 *argv = '\0';
  917.         if ( c == '>' ) switchflag=true;
  918.         str2date(rawdate,
  919.              switchflag ? nextdate->enddate : nextdate->strtdate);
  920.         if ( c == ';' || c == '\0') {  /*  case: -d date  */
  921.             VOID strcpy(nextdate->enddate,nextdate->strtdate);
  922.             VOID sprintf(nextdate->strtdate,DATEFORM,0,0,0,0,0,0);
  923.                     nextdate->dnext = duelst;
  924.                     duelst = nextdate;
  925.             goto end;
  926.         } else {
  927.             /*   case:   -d date<  or -d  date>; see switchflag */
  928.             while ( (c= *++argv) == ' ' || c=='\t' || c=='\n');
  929.             if ( c == ';' || c == '\0') {
  930.             /* second date missing */
  931.             if (switchflag)
  932.                 *nextdate->strtdate= '\0';
  933.             else
  934.                 *nextdate->enddate= '\0';
  935.             nextdate->dnext = datelist;
  936.             datelist = nextdate;
  937.             goto end;
  938.             }
  939.                 }
  940.             }
  941.             rawdate = argv;
  942.         while( c != '>' && c != '<' && c != ';' && c != '\0')
  943.          c = *++argv;
  944.             *argv = '\0';
  945.         str2date(rawdate,
  946.              switchflag ? nextdate->strtdate : nextdate->enddate);
  947.             nextdate->dnext = datelist;
  948.         datelist = nextdate;
  949.      end:
  950.         if ( c == '\0')  return;
  951.             while( (c = *++argv) == ';' || c == ' ' || c == '\t' || c =='\n');
  952.         }
  953. }
  954.  
  955.  
  956.  
  957.     static void
  958. getnumericrev()
  959. /*  function:  get the numeric name of revisions which stored in revlist  */
  960. /*             and then stored the numeric names in Revlst                */
  961. /*             if branchflag, also add default branch                     */
  962.  
  963. {
  964.         struct  Revpairs        * ptr, *pt;
  965.     unsigned n;
  966.     struct buf s, e;
  967.     const struct buf *rstart, *rend;
  968.  
  969.         Revlst = nil;
  970.         ptr = revlist;
  971.     bufautobegin(&s);
  972.     bufautobegin(&e);
  973.         while( ptr ) {
  974.         n = 0;
  975.         rstart = &s;
  976.         rend = &e;
  977.  
  978.         switch (ptr->numfld) {
  979.  
  980.           case 1: /* -r rev */
  981.         if (expandsym(ptr->strtrev, &s)) {
  982.             rend = &s;
  983.             n = countnumflds(s.string);
  984.                 }
  985.         break;
  986.  
  987.           case 2: /* -r rev- */
  988.         if (expandsym(ptr->strtrev, &s)) {
  989.             bufscpy(&e, s.string);
  990.             n = countnumflds(s.string);
  991.             (n<2 ? e.string : strrchr(e.string,'.'))[0]  =  0;
  992.                 }
  993.         break;
  994.  
  995.           case 3: /* -r -rev */
  996.         if (expandsym(ptr->endrev, &e)) {
  997.             if ((n = countnumflds(e.string)) < 2)
  998.             bufscpy(&s, ".1");
  999.             else {
  1000.             bufscpy(&s, e.string);
  1001.             VOID strcpy(strrchr(s.string,'.'), ".1");
  1002.             }
  1003.                 }
  1004.         break;
  1005.  
  1006.           default: /* -r rev1-rev2 */
  1007.         if (
  1008.             expandsym(ptr->strtrev, &s)
  1009.             &&    expandsym(ptr->endrev, &e)
  1010.             &&    checkrevpair(s.string, e.string)
  1011.         ) {
  1012.             n = countnumflds(s.string);
  1013.             /* Swap if out of order.  */
  1014.             if (compartial(s.string,e.string,n) > 0) {
  1015.             rstart = &e;
  1016.             rend = &s;
  1017.             }
  1018.         }
  1019.         break;
  1020.         }
  1021.  
  1022.         if (n) {
  1023.         pt = ftalloc(struct Revpairs);
  1024.         pt->numfld = n;
  1025.         pt->strtrev = fstrsave(rstart->string);
  1026.         pt->endrev = fstrsave(rend->string);
  1027.                 pt->rnext = Revlst;
  1028.                 Revlst = pt;
  1029.         }
  1030.         ptr = ptr->rnext;
  1031.         }
  1032.         /* Now take care of branchflag */
  1033.     if (branchflag && (Dbranch||Head)) {
  1034.         pt = ftalloc(struct Revpairs);
  1035.         pt->strtrev = pt->endrev =
  1036.         Dbranch ? Dbranch : fstrsave(partialno(&s,Head->num,1));
  1037.         pt->rnext=Revlst; Revlst=pt;
  1038.         pt->numfld = countnumflds(pt->strtrev);
  1039.         }
  1040.     bufautoend(&s);
  1041.     bufautoend(&e);
  1042. }
  1043.  
  1044.  
  1045.  
  1046.     static int
  1047. checkrevpair(const char *num1,const char *num2)
  1048. /*  function:  check whether num1, num2 are legal pair,i.e.
  1049.     only the last field are different and have same number of
  1050.     fields( if length <= 2, may be different if first field)   */
  1051.  
  1052. {
  1053.     unsigned length = countnumflds(num1);
  1054.  
  1055.     if (
  1056.             countnumflds(num2) != length
  1057.         ||    2 < length  &&  compartial(num1, num2, length-1) != 0
  1058.     ) {
  1059.         error("invalid branch or revision pair %s : %s", num1, num2);
  1060.             return false;
  1061.         }
  1062.  
  1063.         return true;
  1064. }
  1065.  
  1066.  
  1067.  
  1068.     static void
  1069. getrevpairs(register char *argv)
  1070. /*  function:  get revision or branch range from command line, and   */
  1071. /*             store in revlist                                      */
  1072.  
  1073. {
  1074.         register    char    c;
  1075.         struct      Revpairs  * nextrevpair;
  1076.         int         flag;
  1077.  
  1078.         argv--;
  1079.         while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  1080.                  c == '\n' || c == ';')  ;
  1081.         if ( c == '\0' ) {
  1082.         warn("missing revision or branch number after -r");
  1083.             return;
  1084.         }
  1085.  
  1086.         while( c != '\0') {
  1087.             while(  c  == ',' || c == ' ' || c == '\t' ||
  1088.                      c == '\n' || c == ';') c = *++argv;
  1089.             if (c == '\0')  return;
  1090.         nextrevpair = talloc(struct Revpairs);
  1091.             nextrevpair->rnext = revlist;
  1092.             revlist = nextrevpair;
  1093.         nextrevpair->numfld = 0;
  1094.             nextrevpair->strtrev = nil;
  1095.             nextrevpair->endrev  = nil;
  1096.             flag = false;
  1097.             if (  c == '<' || c == '-' ) {  /*  case: -r -rev  or -r <rev  */
  1098.                 flag = true;
  1099.                 while( (c =(*++argv)) == ' ' || c == '\t' || c =='\n') ;
  1100.             }
  1101.             else {
  1102.                 nextrevpair->strtrev = argv;
  1103.                 /*   get a revision or branch name  */
  1104.                 while( c != ',' && c != ';' && c != ' ' && c != '\0' && c != '-'
  1105.                         && c != '\t' && c != '\n' && c != '<') c = *++argv;
  1106.  
  1107.                 *argv = '\0';
  1108.  
  1109.                 if ( c != '<' && c != '-') {    /*  case: rev  */
  1110.                     nextrevpair->numfld = 1;
  1111.                     continue;
  1112.                 }
  1113.  
  1114.                 if ( (c =(*++argv)) == ',' || c == '\0' || c == ' '
  1115.                       || c == '\t' || c == '\n' || c == ';') {/*  case: rev_  */
  1116.                     nextrevpair->numfld = 2;
  1117.                     continue;
  1118.                 }
  1119.             }
  1120.             nextrevpair->endrev = argv;
  1121.             while( c != ',' && c != ' ' && c != '\0' && c != '\t' && c != '<'
  1122.                    && c != '\n' && c != '-' && c != ';')  c = *++argv;
  1123.  
  1124.             * argv = '\0';
  1125.             if ( c == '<'){
  1126.         error("separator expected near %s", nextrevpair->endrev);
  1127.                 while( (c = *++argv) != ',' && c != ' ' && c != '\0' &&
  1128.                         c != '\t' && c != '\n' && c != ';' ) ;
  1129.                 revlist = nextrevpair->rnext;
  1130.                 continue;
  1131.             }
  1132.             else  {
  1133.                 if (flag)   /*  case:  -rev   */
  1134.                     nextrevpair->numfld  = 3;
  1135.  
  1136.                 else     /*   rev1-rev2  appears  */
  1137.                     nextrevpair->numfld = 4;
  1138.             }
  1139.         }
  1140. }
  1141.